package com.example.myapplication.util;

import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.example.myapplication.R;

public class LoadingUtil {

    /**
     * 创建加载库
     * @param context
     * @return
     */
    public static Dialog createLoadingDialog(Context context) {
        Dialog loadingDialog = new Dialog(context, R.style.loading_dialog);
        loadingDialog.setCancelable(false);
        View view = LayoutInflater.from(context).inflate(R.layout.view_loading, null);
        ImageView iv = view.findViewById(R.id.loading_iv);
        Animator animator = AnimatorInflater.loadAnimator(context, R.animator.loading_anim);
        animator.setTarget(iv);
        animator.start();
        loadingDialog.setContentView(view, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT));
        return loadingDialog;
    }
}
